package com.songshuai.webapi.baseapi.common.enumerations;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum CourseDataEnum {
    Grade(1004, "年级"),
    GiveLessonsType(1029, "授课类型"),
    Stage(1014, "级段(小学，初中，高中)"),
    Season(1024, "周期value"),
    Edition(1025, "版本value"),
    Cyear(1023, "课程年份");
    private int code;
    private String msg;

    CourseDataEnum(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return CourseDataEnum.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return CourseDataEnum.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(Integer code){
        if(code==null||code<=0)
            return "";
        for(CourseDataEnum err : CourseDataEnum.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
